package com.example.hospitallogin.modules.login.controller;

import com.example.hospitallogin.assembly.BaseResponse;
import com.example.hospitallogin.assembly.CustomResultCode;
import com.example.hospitallogin.assembly.PageBaseResponse;
import com.example.hospitallogin.assembly.PageData;
import com.example.hospitallogin.modules.login.bff.HospitalRegisterImpl;
import com.example.hospitallogin.modules.login.dto.ApplyListReq;
import com.example.hospitallogin.modules.login.dto.ApprovalApplyReq;
import com.example.hospitallogin.modules.login.dto.HospitalRegisterRsp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author qiancheng@cqxyy.net
 * @date 2022/9/17
 */
@RestController
@RequestMapping("/manager-setting")
@Api(tags = "管理员设置")
@Validated
public class HospitalRegisterController {

    @Autowired
    private HospitalRegisterImpl hospitalRegister;

    @ApiOperation(value = "同意医院申请")
    @RequestMapping(path = "/approval-apply",method = RequestMethod.POST)
    public BaseResponse approvalApply(@RequestBody @Valid ApprovalApplyReq req){
        String msg = (String)hospitalRegister.approvalApply(req);
        if (!msg.equals("")){
            return BaseResponse.fail(CustomResultCode.ACCOUNTERROR,msg);
        }
        return BaseResponse.success();
    };

    @ApiOperation(value = "拒绝医院申请")
    @RequestMapping(path = "/refuse-apply",method = RequestMethod.DELETE)
    public BaseResponse refuseApply(@RequestBody @Valid ApprovalApplyReq req){
        String msg = (String)hospitalRegister.refuseApply(req);
        if (!msg.equals("")){
            return BaseResponse.fail(CustomResultCode.ACCOUNTERROR,msg);
        }
        return BaseResponse.success();
    };

    @ApiOperation(value = "查看医院申请列表")
    @RequestMapping(path = "/apply-list",method = RequestMethod.POST)
    public PageBaseResponse<HospitalRegisterRsp> applyList(@RequestBody @Valid ApplyListReq req){
        PageData<HospitalRegisterRsp> page = hospitalRegister.applyList(req);
        return PageBaseResponse.success(page);
    }


}
